package common

import (
	"context"
	"git.mycaigou.com/gfyx/micro-gfyx-oppty-service/infrastructure/common/errcode"
	pb "git.mycaigou.com/gfyx/micro-gfyx-oppty-service/proto/micro_gfyx_oppty_service_proto/micro-gfyx-oppty-service/common"
	"git.mycaigou.com/gfyx/micro-gfyx-oppty-service/service/common/verify_code"
)

type verifyCodeServer struct {
	verifyCodeService verify_code.VerifyCodeServiceIface
}

// NewVerifyCodeServer 构造函数
func NewVerifyCodeServer(
	verifyCodeService verify_code.VerifyCodeServiceIface,
) pb.VerifyCodeServiceServer {
	return &verifyCodeServer{
		verifyCodeService: verifyCodeService,
	}
}

// GetCaptcha 获取图形验证码
func (v *verifyCodeServer) GetCaptcha(ctx context.Context, request *pb.GetCaptchaRequest) (*pb.GetCaptchaResponse, error) {
	captchaResponse, err := v.verifyCodeService.GetCaptcha(ctx, request)
	if err != nil {
		return nil, errcode.CTogRPCError(err)
	}
	return captchaResponse, nil
}

// SendSms 发送验证码
func (v *verifyCodeServer) SendSms(ctx context.Context, request *pb.SendSmsRequest) (*pb.SendSmsResponse, error) {
	resp, err := v.verifyCodeService.SendSmsCode(ctx, request)
	if err != nil {
		return nil, err
	}
	return resp, nil
}
